// pages/orders/orders.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderList: [],
    highlight: [],
    paymentStatus:'',
    deliveryStatus:'',
    jsCode: ''
  },
  backOrder: function () {
    wx.navigateBack({
      url: "../order/order"
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.orderList()
    this.setHighlight()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // this.setHighlight(index)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  orderList: function () {
    var that = this;
    wx.login({
      success: function (res) {
        console.log(res)
        that.setData({ jsCode: res.code })
        wx.request({
          url: getApp().globalData.domain + 'api/order/list?openid=' + getApp().globalData.openid + '&jsCode=' + that.data.jsCode,
          data: {},
          header: {
            "Content-Type": "applciation/json"
          },
          method: "GET",
          success: function (res) {
            // console.log(res.data.data);
            // console.log(res.data.data['0']['total_price'])
            // return
            console.log(res.data.data);
            console.log(res.data);
            console.log(res);
            that.setData({
              orderList: res.data
              // paymentStatus:res.data.data
            })
            that.setHighlight(0)
          },
          fail: function (err) { },
          complete: function () { }
        })
      }
    })
    
  },
  tabClick0: function () {
    var that = this;
    wx.login({
      success: function (res) {
        console.log(res)
        that.setData({ jsCode: res.code })
        wx.request({
          url: getApp().globalData.domain + 'api/order/list?openid=' + getApp().globalData.openid + '&jsCode=' + that.data.jsCode,
          data: {},
          header: {
            "Content-Type": "applciation/json"
          },
          method: "GET",
          success: function (res) {
            // console.log(res);
            that.setData({
              orderList: res.data
            })
            that.setHighlight(0)
          },
          fail: function (err) { },
          complete: function () { }
        })
      }
    })
    
  },
  tabClick1: function () {
    var that = this;
    wx.login({
      success: function (res) {
        // console.log(res)
        that.setData({ jsCode: res.code })
        wx.request({
          url: getApp().globalData.domain + 'api/order/already_paid?openid=' + getApp().globalData.openid + '&jsCode=' + that.data.jsCode,
          data: {},
          header: {
            "Content-Type": "applciation/json"
          },
          method: "GET",
          success: function (res) {
            // console.log(res);
            that.setData({
              orderList: res.data
            })
            that.setHighlight(1)
          },
          fail: function (err) { },
          complete: function () { }
        })
      }
    })
    
  },
  tabClick2: function () {
    var that = this;
    wx.login({
      success: function (res) {
        // console.log(res)
        that.setData({ jsCode: res.code })
        wx.request({
          url: getApp().globalData.domain + 'api/order/unpaid?openid=' + getApp().globalData.openid + '&jsCode=' + that.data.jsCode,
          data: {},
          header: {
            "Content-Type": "applciation/json"
          },
          method: "GET",
          success: function (res) {
            // console.log(res);
            that.setData({
              orderList: res.data
            })
            that.setHighlight(2)
          },
          fail: function (err) { },
          complete: function () { }
        })
      }
    })
    
  },
  tabClick3: function () {
    var that = this;
    wx.login({
      success: function (res) {
        // console.log(res)
        that.setData({ jsCode: res.code })
        wx.request({
          url: getApp().globalData.domain + 'api/order/unshippe_delivery?openid=' + getApp().globalData.openid + '&jsCode=' + that.data.jsCode,
          data: {},
          header: {
            "Content-Type": "applciation/json"
          },
          method: "GET",
          success: function (res) {
            that.setData({
              orderList: res.data
            })
            that.setHighlight(3)
          },
          fail: function (err) { },
          complete: function () { }
        })
      }
    })
    
  },
  tabClick4: function () {
    var that = this;
    wx.login({
      success: function (res) {
        // console.log(res)
        that.setData({ jsCode: res.code })
        wx.request({
          url: getApp().globalData.domain + 'api/order/already_shipped?openid=' + getApp().globalData.openid + '&jsCode=' + that.data.jsCode,
          data: {},
          header: {
            "Content-Type": "applciation/json"
          },
          method: "GET",
          success: function (res) {
            that.setData({
              orderList: res.data
            })
            that.setHighlight(4)
          },
          fail: function (err) { },
          complete: function () { }
        })
      }
    })
    
  },
  setHighlight: function (index) {
    // console.log(index)
    var that = this
    var highlight = []
    for (var i = 0; i < 5; i++) {
      highlight[i] = ''
    }
    highlight[index] = 'highlight'
    // console.log(highlight[index])
    that.setData({ highlight: highlight })
    // console.log(that.data.highlight)
  },
})